import { App, Directive } from 'vue';
import { usePermissionStore } from '@/stores/permission';

const permissionDirective: Directive = {
  mounted(el, binding) {
    const store = usePermissionStore();
    const code = binding.value as string;
    if (!store.has(code)) {
      // 没有权限直接移除 DOM
      el.parentNode?.removeChild(el);
    }
  },
};

export default {
  install(app: App) {
    app.directive('permission', permissionDirective);
  },
};